package com.ashen.boot.admin.project.system.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ashen.boot.admin.project.system.user.model.entity.UserDataTypeEntity;
import com.ashen.boot.admin.project.system.user.model.vo.UserDataTypeVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户数据权限类型 Mapper 接口
 * </p>
 *
 * @author gao
 * @since 2021-11-08
 */
@Mapper
public interface IUserDataTypeMapper extends BaseMapper<UserDataTypeEntity> {
    @Select(" <script> SELECT c.isrow as isrow,\n" +
            "        c.permission_type as permission_type,\n" +
            "        c.description as description,\n" +
            "        c.user_id as user_id,\n" +
            "        c.id as id,\n" +
            "        isnull(d.isall,-1) as isall\n" +
            "        FROM   (SELECT  b.isrow,\n" +
            "        b.permission_type,\n" +
            "        b.description,\n" +
            "        a.user_id,\n" +
            "        b.id\n" +
            "        FROM   t_sys_user_account a\n" +
            "        FULL JOIN t_sys_data_permission b\n" +
            "        ON 1 = 1) c\n" +
            "        LEFT OUTER JOIN t_sys_user_data_type d\n" +
            "        ON c.user_id = d.user_id and c.id=d.data_permission_id\n" +
            "        where c.user_id in\n" +
            "        <foreach collection='list' item='item' index='index' open='(' separator=',' close=')'>\n" +
            "            #{item}\n" +
            "        </foreach> </script>")
    List<UserDataTypeVO> listCustom(List<Long> userIds);
}
